<template>
<view class="container">
   <!-- 足迹 -->
   <view class="record">
      <view>为你保留七天记录</view>
      <view @tap="qingkong">
         <image src="/static/remao_shop/img/delete.png"></image>
         <view>清空足迹</view>
      </view>
   </view>
   <!-- 有记录 -->
   <view v-for="(item, index) in shopList" :key="index" v-if="isShow == false" class="recordList">
      <view class="recordListTime">{{item.time}}</view>
      <view class="recordListNav">
         <view class="coupon-list-li">
            <image :src="item.thumb_img"></image>
            <view class="coupon-list-li-title">{{item.goods_name}}</view>
            <!-- <view class="coupon-list-li-text">{{list.brief}}</view> -->
            <view class="coupon-list-li-textTwo">
               <view class="coupon-list-li-money">
                  <text>￥</text>
                  <text>{{item.price}}</text>
               </view>
            </view>
         </view>
      </view>
   </view>		
   <!-- 无记录 -->
   <view v-if="isShow == true" class="noHistory">
      <!-- <image src="../../img/zanwu.png" style="width: 200rpx;height: 200rpx;" ></image> -->
      <view>最近七天没有足迹哦，快去看看吧！</view>
   </view>
</view>
</template>

<script>
// hotmall/packageB/footprint/footprint.js
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      userId: '',
      isShow: false,
      shopList: []
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'userId',
      success: res => {
        console.log(res);
        this.setData({
          userId: res.data
        });
        this.getList();
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getList: function () {
      app.globalData.request({
        url: api.default.footprint,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          user_id: this.userId
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            shopList: res
          });

          if (res.length == 0) {
            this.setData({
              isShow: true
            });
          } else {
            this.setData({
              isShow: false
            });
          }
        }
      });
    },
    //清空足迹
    qkList: function () {
      app.globalData.request({
        url: api.default.footprint_qk,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.userId
        },
        method: 'POST',
        success: res => {
          console.log(res);

          if (res.status == 1) {
            wx.showToast({
              title: res.msg,
              icon: 'success'
            });
          }
        }
      });
    },
    qingkong: function () {
      // wx.showModal({
      //   title: '温馨提示',
      //   content: '是否要清空足迹?',
      //   success(res) {
      //     if (res.confirm) {
      //       wx.showLoading({
      //         title: '加载中',
      //       })
      //       setTimeout(function () {
      //         wx.hideLoading()
      //       }, 1000)
      //       this.qkList()
      //     } else if (res.cancel) {
      //       console.log('用户点击取消')
      //     }
      //   }
      // })
      this.qkList();
      this.getList();
    }
  }
};
</script>
<style>
@import "./footprint.css";
</style>